package tech.aistar.corejava.day15;

/**
 * @author success
 * @version 1.0
 * @description:本类用来演示:后台守护线程或者用户线程
 * @date 2019/8/3 0003
 */
public class DaemonDemo {
    public static void main(String[] args) {
        Thread d1 = new D1();//main
        Thread d2 = new D2();//gc

        //设置为守护线程
        //应用程序只需要关心线程d1是否运行结束
        //不会等d2结束才会结束.
        d2.setDaemon(true);

        d1.start();
        d2.start();
    }
}
class D1 extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 10; i++) {
            System.out.println("d1:"+i);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
/**守护线程**/
class D2 extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 100; i++) {
            System.out.println("d2:"+i);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
